#include <bits/stdc++.h>
#ifndef DEBUG
#define debug
#endif
using namespace std;
using i64 = int64_t;

const int inf = INT_MIN / 2;
int main() {
  cin.tie(0)->sync_with_stdio(0);
  int n;
  cin >> n;
  vector<int> a(n + 1);
  for (int i = 1; i <= n; i ++) cin >> a[i];
  int x1, x2;
  cin >> x1 >> x2;

  vector<vector<int>> dp(n + 1, vector<int>(n + 1));
  vector<vector<vector<int>>> f(n + 1, vector<vector<int>>(n + 1, vector<int>(101, inf)));

  for (int l = n; l >= 1; l --) {
    f[l][l][1] = 0;
    for (int r = l; r <= n; r ++) {
      dp[l][r] = inf;
      int len = r - l + 1;
      // 全部相同
      if (x1 <= len && len <= x2) {
        if (all_of(a.begin() + l, a.begin() + r + 1, [&](int x) { return x == a[l]; })) {
          dp[l][r] = max(dp[l][r], len * len);
        }
      }

      // 划分左右
      for (int k = l; k < r; k ++) {
        dp[l][r] = max(dp[l][r], dp[l][k] + dp[k + 1][r]);
      }

      // A()A()...A
      if (a[l] == a[r]) {
        // f[l][r][c] -> f[l][k][c+1] + dp[k+1][r-1] if (a[k] == a[l])
        for (int k = l; k < r; k ++) {
          if (a[k] == a[l]) {
            for (int c = 2; c <= len; c ++) {
              f[l][r][c] = max(f[l][r][c], f[l][k][c - 1] + dp[k + 1][r - 1]);
            }
          }
        }
        for (int c = x1; c <= x2; c ++) {
          dp[l][r] = max(dp[l][r], f[l][r][c] + c * c);
        }
      }
    }
  }
  vector<int> linear(n + 1);
  linear[0] = 0;
  for (int i = 1; i <= n; i ++) {
    linear[i] = linear[i - 1];
    for (int j = 0; j < i; j ++) {
      linear[i] = max(linear[i], linear[j] + dp[j + 1][i]);
    }
  }
  debug(dp);
  debug(linear);
  cout << linear[n] << endl;
}